package com.oguzhan.xtools.view;

import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.border.TitledBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.ImageIcon;

public class TokenView extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -318315653428914263L;
	private JPasswordField passwordField;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTable table;

	/**
	 * Create the panel.
	 */
	public TokenView() {
		setBorder(new EmptyBorder(2, 5, 0, 5));
		setPreferredSize(new Dimension(800, 600));
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JPanel serverPanel = new JPanel();
		serverPanel.setPreferredSize(new Dimension(0, 0));
		serverPanel.setBorder(new TitledBorder(null, "Servers", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(serverPanel);
		serverPanel.setLayout(new BorderLayout(0, 0));
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(0, 0));
		serverPanel.add(scrollPane, BorderLayout.CENTER);
		
		table = new JTable();
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				"Status", "Server Name", "User/Pass", "Token"
			}
		) {
			/**
			 * 
			 */
			private static final long serialVersionUID = 107400654564395125L;
			boolean[] columnEditables = new boolean[] {
				false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setPreferredWidth(41);
		table.getColumnModel().getColumn(1).setPreferredWidth(73);
		table.getColumnModel().getColumn(2).setPreferredWidth(90);
		table.getColumnModel().getColumn(3).setPreferredWidth(338);
		
		JPanel panel_2 = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		serverPanel.add(panel_2, BorderLayout.SOUTH);
		
		JButton btnAcquireTokens = new JButton("Acquire Tokens");
		btnAcquireTokens.setIcon(new ImageIcon(TokenView.class.getResource("/tr/com/softtech/icons/token-generator.gif")));
		panel_2.add(btnAcquireTokens);
		
		JButton btnAdd = new JButton("Add");
		panel_2.add(btnAdd);
		
		JButton btnEdit = new JButton("Edit");
		panel_2.add(btnEdit);
		
		JButton btnNewButton = new JButton("Remove");
		panel_2.add(btnNewButton);
		
		JPanel configPanel = new JPanel();
		configPanel.setBorder(new EmptyBorder(0, 50, 15, 100));
		configPanel.setPreferredSize(new Dimension(0, 0));
		add(configPanel);
		configPanel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblServerName = new JLabel("Server Name");
		configPanel.add(lblServerName, "2, 2, right, default");
		
		textField_2 = new JTextField();
		configPanel.add(textField_2, "4, 2, fill, default");
		textField_2.setColumns(10);
		
		JLabel lblUrl = new JLabel("URL");
		configPanel.add(lblUrl, "2, 4, right, default");
		
		textField_1 = new JTextField();
		configPanel.add(textField_1, "4, 4, fill, default");
		textField_1.setColumns(10);
		
		JLabel lblUsername = new JLabel("Username");
		configPanel.add(lblUsername, "2, 6, right, default");
		
		textField = new JTextField();
		configPanel.add(textField, "4, 6, fill, default");
		textField.setColumns(10);
		
		JLabel lblPassword = new JLabel("Password");
		configPanel.add(lblPassword, "2, 8, right, default");
		
		passwordField = new JPasswordField();
		configPanel.add(passwordField, "4, 8");
		
		JLabel lblServerType = new JLabel("Server Type");
		configPanel.add(lblServerType, "2, 10, right, default");
		
		JComboBox comboBox = new JComboBox();
		configPanel.add(comboBox, "4, 10");
		
		JPanel panel = new JPanel();
		panel.setBorder(new EmptyBorder(4, 10, 0, 10));
		add(panel);
		panel.setLayout(new BorderLayout(0, 0));
		
		JTextArea textArea = new JTextArea();
		textArea.setBorder(new LineBorder(Color.LIGHT_GRAY));
		panel.add(textArea, BorderLayout.CENTER);
		
		ProgressPanel panel_1 = new ProgressPanel();
		panel.add(panel_1, BorderLayout.SOUTH);

	}

}
